package com.lab.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MySqlSessionFactory {
private static SqlSessionFactory sqlSessionFactory=null;
	
	static{
		//加载数据库配置文件
		InputStream ins=null;
		try {
			ins = Resources.getResourceAsStream("SqlMapConfig.xml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//创建对象SqlSessionFactory对象
		sqlSessionFactory=new SqlSessionFactoryBuilder().build(ins);
	}
	
	public static SqlSession getSqlSession(){
		
		return sqlSessionFactory.openSession();
	}
}
